home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / doom / knbot03.zip / SRC.ZIP / TRIGGERS.QC < prev    next >
Text File  |  1997-03-15  |  16KB  |  667 lines

  1.  
  2. entity stemp, otemp, s, old;
  3.  
  4.  
  5. void() trigger_reactivate =
  6. {
  7.     self.solid = SOLID_TRIGGER;
  8. };
  9.  
  10. //=============================================================================
  11.  
  12. float    SPAWNFLAG_NOMESSAGE = 1;
  13. float    SPAWNFLAG_NOTOUCH = 1;
  14.  
  15. // the wait time has passed, so set back up for another activation
  16. void() multi_wait =
  17. {
  18.     if (self.max_health)
  19.     {
  20.         self.health = self.max_health;
  21.         self.takedamage = DAMAGE_YES;
  22.         self.solid = SOLID_BBOX;
  23.     }
  24. };
  25.  
  26.  
  27. // the trigger was just touched/killed/used
  28. // self.enemy should be set to the activator so it can be held through a delay
  29. // so wait for the delay time before firing
  30. void() multi_trigger =
  31. {
  32.     if (self.nextthink > time)
  33.     {
  34.         return;        // allready been triggered
  35.     }
  36.  
  37.     if (self.classname == "trigger_secret")
  38.     {
  39. // BG Bot - added recognition of "bot" classname
  40.                 if ((self.enemy.classname != "player") && (self.enemy.classname != "bot"))
  41.             return;
  42.                 //if (self.enemy.classname != "bot") // otherwise owner might not know
  43.                 //        bprint ("bot found a secret!\n");
  44.         found_secrets = found_secrets + 1;
  45.         WriteByte (MSG_ALL, SVC_FOUNDSECRET);
  46.     }
  47.  
  48.     if (self.noise)
  49.         sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  50.  
  51. // don't trigger again until reset
  52.     self.takedamage = DAMAGE_NO;
  53.  
  54.     activator = self.enemy;
  55.     
  56.     SUB_UseTargets();
  57.  
  58.     if (self.wait > 0)    
  59.     {
  60.         self.think = multi_wait;
  61.         self.nextthink = time + self.wait;
  62.     }
  63.     else
  64.     {    // we can't just remove (self) here, because this is a touch function
  65.         // called wheil C code is looping through area links...
  66.         self.touch = SUB_Null;
  67.         self.nextthink = time + 0.1;
  68.         self.think = SUB_Remove;
  69.     }
  70. };
  71.  
  72. void() multi_killed =
  73. {
  74.     self.enemy = damage_attacker;
  75.     multi_trigger();
  76. };
  77.  
  78. void() multi_use =
  79. {
  80.     self.enemy = activator;
  81.     multi_trigger();
  82. };
  83.  
  84. void() multi_touch =
  85. {
  86. // BG Bot - added recognition of "bot" classname
  87.         if ((other.classname != "player") && (other.classname != "bot"))
  88.         return;
  89.     
  90. // if the trigger has an angles field, check player's facing direction
  91.     if (self.movedir != '0 0 0')
  92.     {
  93.         makevectors (other.angles);
  94.         if (v_forward * self.movedir < 0)
  95.             return;        // not facing the right way
  96.     }
  97.     
  98.     self.enemy = other;
  99.     multi_trigger ();
  100. };
  101.  
  102. /*QUAKED trigger_multiple (.5 .5 .5) ? notouch
  103. Variable sized repeatable trigger.  Must be targeted at one or more entities.  If "health" is set, the trigger must be killed to activate each time.
  104. If "delay" is set, the trigger waits some time after activating before firing.
  105. "wait" : Seconds between triggerings. (.2 default)
  106. If notouch is set, the trigger is only fired by other entities, not by touching.
  107. NOTOUCH has been obsoleted by trigger_relay!
  108. sounds
  109. 1)    secret
  110. 2)    beep beep
  111. 3)    large switch
  112. 4)
  113. set "message" to text string
  114. */
  115. void() trigger_multiple =
  116. {
  117.     if (self.sounds == 1)
  118.     {
  119.         precache_sound ("misc/secret.wav");
  120.         self.noise = "misc/secret.wav";
  121.     }
  122.     else if (self.sounds == 2)
  123.     {
  124.         precache_sound ("misc/talk.wav");
  125.         self.noise = "misc/talk.wav";
  126.     }
  127.     else if (self.sounds == 3)
  128.     {
  129.         precache_sound ("misc/trigger1.wav");
  130.         self.noise = "misc/trigger1.wav";
  131.     }
  132.     
  133.     if (!self.wait)
  134.         self.wait = 0.2;
  135.     self.use = multi_use;
  136.  
  137.     InitTrigger ();
  138.  
  139.     if (self.health)
  140.     {
  141.         if (self.spawnflags & SPAWNFLAG_NOTOUCH)
  142.             objerror ("health and notouch don't make sense\n");
  143.         self.max_health = self.health;
  144.         self.th_die = multi_killed;
  145.         self.takedamage = DAMAGE_YES;
  146.         self.solid = SOLID_BBOX;
  147.         setorigin (self, self.origin);    // make sure it links into the world
  148.     }
  149.     else
  150.     {
  151.         if ( !(self.spawnflags & SPAWNFLAG_NOTOUCH) )
  152.         {
  153.             self.touch = multi_touch;
  154.         }
  155.     }
  156. };
  157.  
  158.  
  159. /*QUAKED trigger_once (.5 .5 .5) ? notouch
  160. Variable sized trigger. Triggers once, then removes itself.  You must set the key "target" to the name of another object in the level that has a matching
  161. "targetname".  If "health" is set, the trigger must be killed to activate.
  162. If notouch is set, the trigger is only fired by other entities, not by touching.
  163. if "killtarget" is set, any objects that have a matching "target" will be removed when the trigger is fired.
  164. if "angle" is set, the trigger will only fire when someone is facing the direction of the angle.  Use "360" for an angle of 0.
  165. sounds
  166. 1)    secret
  167. 2)    beep beep
  168. 3)    large switch
  169. 4)
  170. set "message" to text string
  171. */
  172. void() trigger_once =
  173. {
  174.     self.wait = -1;
  175.     trigger_multiple();
  176. };
  177.  
  178. //=============================================================================
  179.  
  180. /*QUAKED trigger_relay (.5 .5 .5) (-8 -8 -8) (8 8 8)
  181. This fixed size trigger cannot be touched, it can only be fired by other events.  It can contain killtargets, targets, delays, and messages.
  182. */
  183. void() trigger_relay =
  184. {
  185.     self.use = SUB_UseTargets;
  186. };
  187.  
  188.  
  189. //=============================================================================
  190.  
  191. /*QUAKED trigger_secret (.5 .5 .5) ?
  192. secret counter trigger
  193. sounds
  194. 1)    secret
  195. 2)    beep beep
  196. 3)
  197. 4)
  198. set "message" to text string
  199. */
  200. void() trigger_secret =
  201. {
  202.     total_secrets = total_secrets + 1;
  203.     self.wait = -1;
  204.     if (!self.message)
  205.         self.message = "You found a secret area!";
  206.     if (!self.sounds)
  207.         self.sounds = 1;
  208.     
  209.     if (self.sounds == 1)
  210.     {
  211.         precache_sound ("misc/secret.wav");
  212.         self.noise = "misc/secret.wav";
  213.     }
  214.     else if (self.sounds == 2)
  215.     {
  216.         precache_sound ("misc/talk.wav");
  217.         self.noise = "misc/talk.wav";
  218.     }
  219.  
  220.     trigger_multiple ();
  221. };
  222.  
  223. //=============================================================================
  224.  
  225.  
  226. void() counter_use =
  227. {
  228. // BG Bot - uses the bot_ext.qc version of counter_use for bots
  229.     if (activator.classname == "bot")
  230.     {
  231.         bot_counter_use ();
  232.         return;
  233.     }
  234.  
  235.     local string junk;
  236.  
  237.     self.count = self.count - 1;
  238.     if (self.count < 0)
  239.         return;
  240.     
  241.     if (self.count != 0)
  242.     {
  243.         if (activator.classname == "player"
  244.         && (self.spawnflags & SPAWNFLAG_NOMESSAGE) == 0)
  245.         {
  246.             if (self.count >= 4)
  247.                 centerprint (activator, "There are more to go...");
  248.             else if (self.count == 3)
  249.                 centerprint (activator, "Only 3 more to go...");
  250.             else if (self.count == 2)
  251.                 centerprint (activator, "Only 2 more to go...");
  252.             else
  253.                 centerprint (activator, "Only 1 more to go...");
  254.         }
  255.         return;
  256.     }
  257.     
  258.     if (activator.classname == "player"
  259.     && (self.spawnflags & SPAWNFLAG_NOMESSAGE) == 0)
  260.         centerprint(activator, "Sequence completed!");
  261.     self.enemy = activator;
  262.     multi_trigger ();
  263. };
  264.  
  265. /*QUAKED trigger_counter (.5 .5 .5) ? nomessage
  266. Acts as an intermediary for an action that takes multiple inputs.
  267.  
  268. If nomessage is not set, t will print "1 more.. " etc when triggered and "sequence complete" when finished.
  269.  
  270. After the counter has been triggered "count" times (default 2), it will fire all of it's targets and remove itself.
  271. */
  272. void() trigger_counter =
  273. {
  274.     self.wait = -1;
  275.     if (!self.count)
  276.         self.count = 2;
  277.  
  278.     self.use = counter_use;
  279. };
  280.  
  281.  
  282. /*
  283. ==============================================================================
  284.  
  285. TELEPORT TRIGGERS
  286.  
  287. ==============================================================================
  288. */
  289.  
  290. float    PLAYER_ONLY    = 1;
  291. float    SILENT = 2;
  292.  
  293. void() play_teleport =
  294. {
  295.     local    float v;
  296.     local    string tmpstr;
  297.  
  298.     v = random() * 5;
  299.     if (v < 1)
  300.         tmpstr = "misc/r_tele1.wav";
  301.     else if (v < 2)
  302.         tmpstr = "misc/r_tele2.wav";
  303.     else if (v < 3)
  304.         tmpstr = "misc/r_tele3.wav";
  305.     else if (v < 4)
  306.         tmpstr = "misc/r_tele4.wav";
  307.     else
  308.         tmpstr = "misc/r_tele5.wav";
  309.  
  310.     sound (self, CHAN_VOICE, tmpstr, 1, ATTN_NORM);
  311.     remove (self);
  312. };
  313.  
  314. void(vector org) spawn_tfog =
  315. {
  316.     s = spawn ();
  317.     s.origin = org;
  318.     s.nextthink = time + 0.2;
  319.     s.think = play_teleport;
  320.  
  321.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  322.     WriteByte (MSG_BROADCAST, TE_TELEPORT);
  323.     WriteCoord (MSG_BROADCAST, org_x);
  324.     WriteCoord (MSG_BROADCAST, org_y);
  325.     WriteCoord (MSG_BROADCAST, org_z);
  326. };
  327.  
  328.  
  329. void() tdeath_touch =
  330. {
  331.     if (other == self.owner)
  332.         return;
  333.  
  334. // frag anyone who teleports in on top of an invincible player
  335.  
  336. // BG Bot - added recognition for classname "bot"
  337.         if ((other.classname == "player") && (other.classname == "bot")) // && was ||
  338.     {
  339.         if (other.invincible_finished > time)
  340.             self.classname = "teledeath2";
  341.                 if (self.owner.classname != "player" && self.owner.classname != "bot")
  342.         {    // other monsters explode themselves
  343.             T_Damage (self.owner, self, self, 50000);
  344.             return;
  345.         }
  346.         
  347.     }
  348.  
  349.     if (other.health)
  350.     {
  351.         T_Damage (other, self, self, 50000);
  352.     }
  353. };
  354.  
  355.  
  356. void(vector org, entity death_owner) spawn_tdeath =
  357. {
  358.         local entity    death;
  359.  
  360.     death = spawn();
  361.     death.classname = "teledeath";
  362.     death.movetype = MOVETYPE_NONE;
  363.     death.solid = SOLID_TRIGGER;
  364.     death.angles = '0 0 0';
  365.     setsize (death, death_owner.mins - '1 1 1', death_owner.maxs + '1 1 1');
  366.     setorigin (death, org);
  367.     death.touch = tdeath_touch;
  368.     death.nextthink = time + 0.2;
  369.     death.think = SUB_Remove;
  370.     death.owner = death_owner;
  371.  
  372.     force_retouch = 2;        // make sure even still objects get hit
  373. };
  374.  
  375. void() teleport_touch =
  376. {
  377. local entity    t;
  378. local vector    org;
  379.  
  380.     if (self.targetname)
  381.     {
  382.         if (self.nextthink < time)
  383.         {
  384.             return;        // not fired yet
  385.         }
  386.     }
  387.  
  388.     if (self.spawnflags & PLAYER_ONLY)
  389.     {
  390. // BG Bot - added recognition for classname "bot"
  391.                 if (other.classname != "player" && other.classname != "bot") // && was ||
  392.             return;
  393.     }
  394.  
  395. // only teleport living creatures
  396.     if (other.health <= 0 || other.solid != SOLID_SLIDEBOX)
  397.         return;
  398.  
  399.     SUB_UseTargets ();
  400.  
  401. // put a tfog where the player was
  402.     spawn_tfog (other.origin);
  403.  
  404.     t = find (world, targetname, self.target);
  405.     if (!t)
  406.         objerror ("couldn't find target");
  407.         
  408. // spawn a tfog flash in front of the destination
  409.     makevectors (t.mangle);
  410.     org = t.origin + 32 * v_forward;
  411.  
  412.     spawn_tfog (org);
  413.     spawn_tdeath(t.origin, other);
  414.  
  415. // move the player and lock him down for a little while
  416.     if (!other.health)
  417.     {
  418.         other.origin = t.origin;
  419.         other.velocity = (v_forward * other.velocity_x) + (v_forward * other.velocity_y);
  420.         return;
  421.     }
  422.  
  423.     setorigin (other, t.origin);
  424.     other.angles = t.mangle;
  425. // BG Bot - added recognition of "bot" classname
  426.         if ((other.classname == "player") || (other.classname == "bot"))
  427.     {
  428.         other.fixangle = 1;        // turn this way immediately
  429.         other.teleport_time = time + 0.7;
  430.         if (other.flags & FL_ONGROUND)
  431.             other.flags = other.flags - FL_ONGROUND;
  432.         other.velocity = v_forward * 300;
  433.     }
  434.     other.flags = other.flags - other.flags & FL_ONGROUND;
  435. };
  436.  
  437. /*QUAKED info_teleport_destination (.5 .5 .5) (-8 -8 -8) (8 8 32)
  438. This is the destination marker for a teleporter.  It should have a "targetname" field with the same value as a teleporter's "target" field.
  439. */
  440. void() info_teleport_destination =
  441. {
  442. // this does nothing, just serves as a target spot
  443.     self.mangle = self.angles;
  444.     self.angles = '0 0 0';
  445.     self.model = "";
  446.     self.origin = self.origin + '0 0 27';
  447.     if (!self.targetname)
  448.         objerror ("no targetname");
  449. };
  450.  
  451. void() teleport_use =
  452. {
  453.     self.nextthink = time + 0.2;
  454.     force_retouch = 2;        // make sure even still objects get hit
  455.     self.think = SUB_Null;
  456. };
  457.  
  458. /*QUAKED trigger_teleport (.5 .5 .5) ? PLAYER_ONLY SILENT
  459. Any object touching this will be transported to the corresponding info_teleport_destination entity. You must set the "target" field, and create an object with a "targetname" field that matches.
  460.  
  461. If the trigger_teleport has a targetname, it will only teleport entities when it has been fired.
  462. */
  463. void() trigger_teleport =
  464. {
  465.     local vector o;
  466.  
  467.     InitTrigger ();
  468.     self.touch = teleport_touch;
  469.     // find the destination 
  470.     if (!self.target)
  471.         objerror ("no target");
  472.     self.use = teleport_use;
  473.  
  474.     if (!(self.spawnflags & SILENT))
  475.     {
  476.         precache_sound ("ambience/hum1.wav");
  477.         o = (self.mins + self.maxs)*0.5;
  478.         ambientsound (o, "ambience/hum1.wav",0.5 , ATTN_STATIC);
  479.     }
  480. };
  481.  
  482. /*
  483. ==============================================================================
  484.  
  485. trigger_setskill
  486.  
  487. ==============================================================================
  488. */
  489.  
  490. void() trigger_skill_touch =
  491. {
  492.         if ((other.classname != "player") && (other.classname != "bot"))
  493.         return;
  494.         
  495.     cvar_set ("skill", self.message);
  496. };
  497.  
  498. /*QUAKED trigger_setskill (.5 .5 .5) ?
  499. sets skill level to the value of "message".
  500. Only used on start map.
  501. */
  502. void() trigger_setskill =
  503. {
  504.     InitTrigger ();
  505.     self.touch = trigger_skill_touch;
  506. };
  507.  
  508.  
  509. /*
  510. ==============================================================================
  511.  
  512. ONLY REGISTERED TRIGGERS
  513.  
  514. ==============================================================================
  515. */
  516.  
  517. void() trigger_onlyregistered_touch =
  518. {
  519. // BG Bot - uses bot_ext.qc version for bots
  520.     if (other.classname == "bot")
  521.                 return;
  522.     if (other.classname != "player")
  523.         return;
  524.     if (self.attack_finished > time)
  525.         return;
  526.  
  527.     self.attack_finished = time + 2;
  528.     if (cvar("registered"))
  529.     {
  530.         self.message = "";
  531.         SUB_UseTargets ();
  532.         remove (self);
  533.     }
  534.     else
  535.     {
  536.         if (self.message != "")
  537.         {
  538.             centerprint (other, self.message);
  539.             sound (other, CHAN_BODY, "misc/talk.wav", 1, ATTN_NORM);
  540.         }
  541.     }
  542. };
  543.  
  544. /*QUAKED trigger_onlyregistered (.5 .5 .5) ?
  545. Only fires if playing the registered version, otherwise prints the message
  546. */
  547. void() trigger_onlyregistered =
  548. {
  549.     precache_sound ("misc/talk.wav");
  550.     InitTrigger ();
  551.     self.touch = trigger_onlyregistered_touch;
  552. };
  553.  
  554. //============================================================================
  555.  
  556. void() hurt_on =
  557. {
  558.     self.solid = SOLID_TRIGGER;
  559.     self.nextthink = -1;
  560. };
  561.  
  562. void() hurt_touch =
  563. {
  564.     if (other.takedamage)
  565.     {
  566.         self.solid = SOLID_NOT;
  567.         T_Damage (other, self, self, self.dmg);
  568.         self.think = hurt_on;
  569.         self.nextthink = time + 1;
  570.     }
  571.  
  572.     return;
  573. };
  574.  
  575. /*QUAKED trigger_hurt (.5 .5 .5) ?
  576. Any object touching this will be hurt
  577. set dmg to damage amount
  578. defalt dmg = 5
  579. */
  580. void() trigger_hurt =
  581. {
  582.     InitTrigger ();
  583.     self.touch = hurt_touch;
  584.     if (!self.dmg)
  585.         self.dmg = 5;
  586. };
  587.  
  588. //============================================================================
  589.  
  590. float PUSH_ONCE = 1;
  591.  
  592. void() trigger_push_touch =
  593. {
  594.     if (other.classname == "grenade")
  595.         other.velocity = self.speed * self.movedir * 10;
  596.     else if (other.health > 0)
  597.     {
  598.         other.velocity = self.speed * self.movedir * 10;
  599.  
  600. // BG Bot - added recognition of "bot" classname
  601.                 if ((other.classname == "player") || (other.classname == "bot"))
  602.         {
  603.             if (other.fly_sound < time)
  604.             {
  605.                 other.fly_sound = time + 1.5;
  606.                 sound (other, CHAN_AUTO, "ambience/windfly.wav", 1, ATTN_NORM);
  607.  
  608. // BG Bot - added notification for the bot's owner
  609.                 if (other.classname == "bot")
  610.                                         bprint ("bot pushed a trigger\n");
  611.             }
  612.         }
  613.     }
  614.     if (self.spawnflags & PUSH_ONCE)
  615.         remove(self);
  616. };
  617.  
  618.  
  619. /*QUAKED trigger_push (.5 .5 .5) ? PUSH_ONCE
  620. Pushes the player
  621. */
  622. void() trigger_push =
  623. {
  624.     InitTrigger ();
  625.     precache_sound ("ambience/windfly.wav");
  626.     self.touch = trigger_push_touch;
  627.     if (!self.speed)
  628.         self.speed = 1000;
  629. };
  630.  
  631. //============================================================================
  632.  
  633. void() trigger_monsterjump_touch =
  634. {
  635.     if ( other.flags & (FL_MONSTER | FL_FLY | FL_SWIM) != FL_MONSTER )
  636.         return;
  637.  
  638. // set XY even if not on ground, so the jump will clear lips
  639.     other.velocity_x = self.movedir_x * self.speed;
  640.     other.velocity_y = self.movedir_y * self.speed;
  641.     
  642.     if ( !(other.flags & FL_ONGROUND) )
  643.         return;
  644.     
  645.     other.flags = other.flags - FL_ONGROUND;
  646.  
  647.     other.velocity_z = self.height;
  648. };
  649.  
  650. /*QUAKED trigger_monsterjump (.5 .5 .5) ?
  651. Walking monsters that touch this will jump in the direction of the trigger's angle
  652. "speed" default to 200, the speed thrown forward
  653. "height" default to 200, the speed thrown upwards
  654. */
  655. void() trigger_monsterjump =
  656. {
  657.     if (!self.speed)
  658.         self.speed = 200;
  659.     if (!self.height)
  660.         self.height = 200;
  661.     if (self.angles == '0 0 0')
  662.         self.angles = '0 360 0';
  663.     InitTrigger ();
  664.     self.touch = trigger_monsterjump_touch;
  665. };
  666.  
  667.